package com.qfedu.wfx.manager.goods.controller;

import com.qfedu.wfx.manager.goods.po.WxbGood;
import com.qfedu.wfx.manager.goods.service.IgoodService;
import com.qfedu.wfx.manager.vo.JsonResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
@RequestMapping("good")
public class GoodsController {
    @Autowired
    private IgoodService igoodService;
    @RequestMapping("list")
    public String findGoods(Model model){
        List<WxbGood> wxbGoods = igoodService.queryAllGoods();
        model.addAttribute("goodList",wxbGoods);
        return "goods-list";
    }

    @RequestMapping("update")
    @ResponseBody
    public JsonResultVO updateState(int state,String goodId){
        JsonResultVO jsonResultVO = new JsonResultVO();
        try {
            igoodService.updateGoodsState(state,goodId);
            jsonResultVO.setCode(1);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResultVO.setCode(0);
        }
        return jsonResultVO;
    }
}
